import http from '@/axios'
import { handleSuccess, handleError } from '@/utils/responseHandler'

/**
 * 案件申请相关API
 */
export const LawyerApi = {
    /**
     * 获取律师列表
     */
    getLawyerList: () =>
        http.get('/lawyer/list')
            .then(res => handleSuccess(res, '获取律师列表成功'))
            .catch(error => handleError(
                error,
                '获取律师列表失败',
                '请检查查询条件或网络连接'
            )),


    /**
     * 获取律师详情
     * @param {number} lawyerId - 律师ID
     */
    getLawyerInfo: (lawyerId) =>
        http.get(`/lawyer/info/${lawyerId}`)
            .then(res => handleSuccess(res, '获取律师信息成功'))
            .catch(error => handleError(
                error,
                '获取律师信息失败',
                '律师可能不存在'
            )),

    /**
     * 更新律师信息
     * @param {Object} infoDTO - 律师信息
     */
    updateLawyerInfo: (infoDTO) =>
        http.put('/lawyer/info', infoDTO)
            .then(res => handleSuccess(res, '律师信息更新成功'))
            .catch(error => handleError(
                error,
                '律师信息更新失败',
                '请检查输入信息'
            )),

    /**
     * 获取律师绩效
     * @param {number} lawyerId - 律师ID
     */
    getPerformance: (lawyerId) =>
        http.get(`/lawyer/performance/${lawyerId}`)
            .then(res => handleSuccess(res, '获取律师绩效成功'))
            .catch(error => handleError(
                error,
                '获取律师绩效失败',
                '请重试'
            )),

    /**
     * 获取所有律师绩效列表
     */
    listPerformance: () =>
        http.get('/lawyer/performance/list')
            .then(res => handleSuccess(res, '获取绩效列表成功'))
            .catch(error => handleError(
                error,
                '获取绩效列表失败',
                '请重试'
            )),

    /**
     * 分配案件给律师
     * @param {Object} assignDTO - 案件分配信息
     * @param {number} assignDTO.lawyerId - 律师ID
     * @param {number} assignDTO.caseId - 案件ID
     */
    assignCaseToLawyer: (assignDTO) =>
        http.post('/lawyer/assign', assignDTO)
            .then(res => handleSuccess(res, '案件分派成功'))
            .catch(error => handleError(
                error,
                '案件分派失败',
                '请检查分配信息'
            )),

    /**
     * 搜索律师
     * @param {Object} searchDTO - 搜索条件
     * @param {string} [searchDTO.name] - 律师姓名
     * @param {string} [searchDTO.specialty] - 专业领域
     * @param {string} [searchDTO.serviceArea] - 服务区域
     * @param {number} [searchDTO.page] - 页码
     * @param {number} [searchDTO.pageSize] - 每页条数
     */
    searchLawyers: (searchDTO) =>
        http.get('/lawyer/search', { params: searchDTO })
            .then(res => handleSuccess(res, '搜索律师成功'))
            .catch(error => handleError(
                error,
                '搜索律师失败',
                '请检查搜索条件'
            ))
}